#ifndef QSAFEBYTEARRAY_H
#define QSAFEBYTEARRAY_H

#include <QObject>
#include <QByteArray>

class QSafeByteArray : public QObject
{
	Q_OBJECT

public:
	QSafeByteArray();
	QSafeByteArray ( const char * str );
	QSafeByteArray ( const char * data, int size ); 
	QSafeByteArray ( int size, char ch ); 
	QSafeByteArray ( int size, Qt::Initialization );
	QSafeByteArray ( const QByteArray & other ); 
	QSafeByteArray ( const QSafeByteArray & other ); 
	~QSafeByteArray();

    QSafeByteArray & operator=(const QByteArray &);
    QSafeByteArray & operator=(const QSafeByteArray &);
    QSafeByteArray & operator=(const char *str);

	operator QByteArray () const;
	QByteArray & byteArray() const;

	static void setEnabled(bool, QObject * handler = 0, const char * slot = 0);
	static size_t compactHeap();
	static bool memoryIsEnough();
	static void setHeapInfo(unsigned long flag);

	struct Exception
	{
		enum Type {Unknown = 0, Allocation = 1};
		Type type;
		size_t size;
		Exception(): type(Unknown), size(0) {}
		Exception(Type t, size_t s): type(t), size(s) {}
	};
signals:
	void error(QSafeByteArray::Exception);
private:
	struct Data;
	Data * d;
};

#endif // QSAFEBYTEARRAY_H
